package com.zhentao.controller;

import com.zhentao.config.Result;
import com.zhentao.pojo.TbWrongQuestions;
import com.zhentao.service.TbWrongQuestionsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 错题相关接口
 */
@RestController
@RequestMapping("/wrong")
public class WrongControllerLjy {

    @Autowired
    private TbWrongQuestionsService tbWrongQuestionsService;

    /**
     * 仅保存四个字段：题目、答案、正确答案、错误原因
     */
    @PostMapping("/add")
    public Result<Long> addWrongQuestion(@RequestBody TbWrongQuestions req) {
        TbWrongQuestions entity = new TbWrongQuestions();
        entity.setQuestionContent(req.getQuestionContent());
        entity.setUserAnswer(req.getUserAnswer());
        entity.setCorrectAnswer(req.getCorrectAnswer());
        entity.setReason(req.getReason());

        boolean saved = tbWrongQuestionsService.save(entity);
        if (saved) {
            return Result.success(entity.getId());
        } else {
            return Result.error("保存失败");
        }
    }
}
